package com.cbank.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.cbank.domain.DistinctPhone;
@Repository
public interface DistinctPhoneDao {
	String ALL = "id,phone,status,name,company,remark,update_time,create_time";

	@Insert("insert into distinct_phone(phone,status,name,company,remark) values(#{phone},#{status},#{name},#{company},#{remark})")
	@Options(useGeneratedKeys = true)
    void insert(DistinctPhone obj);
	
	@Select("select " + ALL + " from distinct_phone where id = #{id} and status = 1 limit 1")
    DistinctPhone getById(Long id);
	
	@Select("select " + ALL + " from distinct_phone where phone = #{phone} and status = 1 limit 1")
    DistinctPhone getByPhone(String phone);

	@Select("select " + ALL + " from distinct_phone where status = 1 limit #{index},#{offset}")
    List<DistinctPhone> getPage(@Param(value = "index") int index, @Param(value = "offset") int offset);
	
	@Select("select " + ALL + " from distinct_phone where status = 1 order by create_time DESC limit #{index},#{offset}")
    List<DistinctPhone> getPageWithParam(@Param(value = "index") int index, @Param(value = "offset") int offset);
	
	@Select("select count(0) from distinct_phone where status = 1")
    int getCount();
	@Select("select count(0) from distinct_phone where phone = #{phone} limit 1")
    int getPhoneCount(String phone);

	@Update("update distinct_phone set status = 0 where phone = #{phone} limit 1")
    void updateInvalid(String phone);
}
